package org.example.servide.lmpl;

import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "toPay420",consumerGroup = "toPay420-group")
public class RocketServicelmpl implements RocketMQListener<MessageExt> {

    @Autowired
    RedissonClient redissonClient;

    @Override
    public void onMessage(MessageExt messageExt) {
        String msgId = messageExt.getMsgId();
        RLock lock = redissonClient.getLock(msgId);
        boolean b = lock.tryLock();
        if(b){
            try {
                SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
                simpleMailMessage.setTo();
            }finally {
                if(lock!=null && lock.isLocked()){
                    lock.unlock();
                }
            }
        }
    }
}
